<?php
namespace admin\action;

use herosphp\http\HttpRequest;
use herosphp\utils\AjaxResult;
use herosphp\bean\Beans;

/**--tmpl-use--**/

class SecurityAction extends CommonAction {

	public function C_start()
	{
		parent::C_start();	
		/**--tmpl-starttodo--**/
	}


	protected $serviceBean="admin.adminSetting.service";

	public function index(HttpRequest $request) {
	
	
		/**--tmpl-addtodo--**/
		$settingItems = array(
			'denyLoginIp',
			'verifyCode' ,
			'onePointLogin',
			'sessionExpr' ,
			'prohibitedWords'
		);


		$service = Beans::get($this->getServiceBean());
		$configs = $service->getSettings($settingItems);
		$configs['denyLoginIp'] = $configs['denyLoginIp']==''?array():explode(',',$configs['denyLoginIp']);
		$configs['prohibitedWords'] = $configs['prohibitedWords']==''?array():explode(',',$configs['prohibitedWords']);

		
		$this->assign('configs',$configs);
	
		$this->assign("title", "安全中心");
		$this->assign('bread', array('网站设置',$this->getTemplateVar('title')));
		$this->assign('breadUrl',  array('javascript:;','javascript:;'));
		$this->setView('security/index');
	
	}
	
	
	/**-- doEditMethod --**/
	public function do_edit(HttpRequest $request){
		$data = $request->getParameter('data');
	
		$data['verifyCode'] = $data['verifyCode'] ? 'on' : 'off';
		$data['onePointLogin'] = $data['onePointLogin'] ? 'on' : 'off';
		$data['prohibitedWords'] = implode(',',$data['prohibitedWords']);
		$data['denyLoginIp'] = implode(',',$data['denyLoginIp']);

		$service = Beans::get($this->getServiceBean());
		if($service->setConfigs($data)){
			AjaxResult::ajaxSuccessResult();
		}
		AjaxResult::ajaxFailtureResult();

	}
	
	

}
